package org.cwnuit.train.utils;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.cwnuit.train.domain.Learns;
import org.cwnuit.train.domain.Notices;
import org.cwnuit.train.domain.RuleStime;
import org.cwnuit.train.domain.Rules;
import org.cwnuit.train.domain.Stime;
import org.cwnuit.train.domain.Sworks;
import org.cwnuit.train.domain.Trains;
import org.cwnuit.train.domain.Users;
import org.cwnuit.train.domain.Wtype;

public class EntityUtil {

	// 将RS结果转化成Entity(Trains)
	public static Trains RsToTrain(ResultSet rs) {
		Trains train = null;
		try {
			train = new Trains();
			train.setTid(rs.getInt("tid"));
			train.setTname(rs.getString("tname"));
			train.setTstate(rs.getInt("tstate"));
			train.setTadvice(rs.getString("tadvice"));
			train.setShtstate(rs.getInt("shtstate"));
			train.setTman(rs.getString("tman"));
			train.setTphone(rs.getString("tphone"));
			train.setCankao(rs.getString("cankao"));

		} catch (SQLException e) {
			e.printStackTrace();
		}
		return train;
	}

	// 将RS结果转化成Entity(Users)
	public static Users RsToUser(ResultSet rs) throws SQLException {
		Users user = null;
		try {
			user = new Users();
			user.setUid(rs.getInt("uid"));
			user.setTid(rs.getInt("tid"));
			user.setUname(rs.getString("uname"));
			user.setUpass(rs.getString("upass"));
			user.setUface(rs.getString("uface"));
			user.setUrole(rs.getInt("urole"));
			user.setWid(rs.getInt("wid"));
			user.setUaddtime(rs.getDate("uaddtime"));
			user.setUlogintime(rs.getDate("ulogintime"));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}

	// 将RS结果转化成Entity(Rules)
	public static Rules RsToRule(ResultSet rs) throws SQLException {
		Rules rule = null;
		try {
			rule = new Rules();
			rule.setRid(rs.getInt("rid"));
			rule.setPid(rs.getInt("pid"));
			rule.setRlevel(rs.getInt("rlevel"));
			rule.setLearntime(rs.getInt("learntime"));
			rule.setRname(rs.getString("rname"));
			rule.setRcommon(rs.getString("rcommon"));
			rule.setRtdbrule(rs.getString("rtdbrule"));
			rule.setRtljrule(rs.getString("rtljrule"));
			rule.setRcwdrule(rs.getString("rcwdrule"));
			rule.setRaddman(rs.getString("raddman"));
			rule.setRaddtime(rs.getDate("raddtime"));
			rule.setRupdatetime(rs.getDate("rupdatetime"));

		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rule;
	}

	// 将RS结果转化成Entity(Sworks)
	public static Sworks RsToSwork(ResultSet rs) throws SQLException {
		Sworks swork = null;
		try {
			swork = new Sworks();
			swork.setSid(rs.getInt("sid"));
			swork.setTid(rs.getInt("tid"));
			swork.setRid(rs.getInt("rid"));
			swork.setScontent(rs.getString("scontent"));
			swork.setScommon(rs.getString("scommon"));
			swork.setSaddtime(rs.getDate("saddtime"));
			swork.setSupdatetime(rs.getDate("supdatetime"));
			swork.setStime(rs.getInt("stime"));
			swork.setSsstate(rs.getInt("ssstate"));
			swork.setSdstate(rs.getInt("sdstate"));
			swork.setState(rs.getInt("state"));
			swork.setSspasstime(rs.getDate("sspasstime"));
			swork.setSdspasstime(rs.getDate("sdspasstime"));
			swork.setSsadvice(rs.getString("ssadvice"));
			swork.setSdadvice(rs.getString("sdadvice"));

		} catch (SQLException e) {
			e.printStackTrace();
		}
		return swork;
	}

	// 将RS结果转化成Entity(Learn)
	public static Learns RsToLearn(ResultSet rs) throws SQLException {
		Learns learn = null;
		try {
			learn = new Learns();
			learn.setLid(rs.getInt("lid"));
			learn.setSid(rs.getInt("sid"));
			learn.setUid(rs.getInt("uid"));
			learn.setLnum(rs.getInt("lnum"));
			learn.setLremark(rs.getString("lremark"));
			learn.setLastltime(rs.getDate("lastltime"));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return learn;
	}
	
	// 将RS结果转化成Entity(Notice)
	public static Notices RsToNotice(ResultSet rs) throws SQLException {
		Notices motice = null;
		try {
			motice = new Notices();
			motice.setNid(rs.getInt("nid"));
			motice.setNrole(rs.getString("nrole"));
			motice.setNtitle(rs.getString("ntitle"));
			motice.setNcontent(rs.getString("ncontent"));
			motice.setNtime(rs.getDate("ntime"));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return motice;
	}
	
	// 将RS结果转化成Entity(Wtype)
	public static Wtype RsToWtype(ResultSet rs) throws SQLException {
		Wtype wtype = null;
		try {
			wtype = new Wtype();
			wtype.setWid(rs.getInt("wid"));
			wtype.setWname(rs.getString("wname"));
			wtype.setWremark(rs.getString("wremark"));
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return wtype;
	}
	
	// 将RS结果转化成Entity(Stime)
	public static Stime RsToStime(ResultSet rs) throws SQLException {
		Stime wtype = null;
		try {
			wtype = new Stime();
			wtype.setSid(rs.getInt("sid"));
			wtype.setWid(rs.getInt("wid"));
			wtype.setSstate(rs.getInt("sstate"));
			wtype.setSname(rs.getString("sname"));
			wtype.setSaddtime(rs.getDate("saddtime"));
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return wtype;
	}
	
	// 将RS结果转化成Entity(RuleStime)
	public static RuleStime RsToRuleStime(ResultSet rs) throws SQLException {
		RuleStime wtype = null;
		try {
			wtype = new RuleStime();
			wtype.setSid(rs.getInt("sid"));
			wtype.setRid(rs.getInt("rid"));
			wtype.setRsid(rs.getInt("rsid"));
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return wtype;
	}

}
